package com.yang.job.enums;

public enum JobExecuteStrategyEnum {
    IMMEDIATE_EXECUTE("immediate", "立即执行"),
    ONCE("once", "执行一次"),
    WITH_FIXED_DELAY("withFixedDelay", "任务执行完毕后间隔执行"),
    WITH_FIXED_RATE("withFixedRate", "任务执行开始后间隔执行");

    private String name;

    private String description;

    JobExecuteStrategyEnum(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public String getName() {
        return this.name;
    }

    public static JobExecuteStrategyEnum getJobExecuteStrategyByName(String name) {
        if (name == null) {
            return null;
        }
        for (JobExecuteStrategyEnum value : values()) {
            if (name.equals(value.getName())) {
                return value;
            }
        }
        return null;
    }

    public static boolean isLegal(String name) {
        JobExecuteStrategyEnum jobExecuteStrategyByName = getJobExecuteStrategyByName(name);
        return jobExecuteStrategyByName != null;
    }

    public String getDescription() {
        return description;
    }
}
